package ch.unisi.inf.pfii.teamred.pacman.view;

import java.awt.Image;
import java.util.HashMap;

import javax.swing.ImageIcon;

/**
 * SpriteLibrary stores all the images (sprites) of the game.
 * 
 * @author mark.pruneri@lu.unisi.ch
 * 
 */

public final class SpriteLibrary {

	private static final String BORDER_PATH = "images/border/";
	private static final String CREATURE_PATH = "images/creature/";
	private static final String BONUS_PATH = "images/bonus/";

	private static SpriteLibrary instance = new SpriteLibrary();
	private static HashMap<String, ImageIcon> images;

	public static SpriteLibrary getInstance() {
		return instance;
	}

	private SpriteLibrary() {
		images = new HashMap<String, ImageIcon>();

		// borders
		images.put("border", loadImage(BORDER_PATH + "border.png"));
		images.put("border1", loadImage(BORDER_PATH + "border1.png"));
		images.put("border2", loadImage(BORDER_PATH + "border2.png"));
		images.put("border3", loadImage(BORDER_PATH + "border3.png"));
		images.put("border4", loadImage(BORDER_PATH + "border4.png"));
		images.put("border5", loadImage(BORDER_PATH + "border5.png"));
		images.put("border6", loadImage(BORDER_PATH + "border6.png"));
		images.put("border7", loadImage(BORDER_PATH + "border7.png"));
		images.put("border8", loadImage(BORDER_PATH + "border8.png"));
		images.put("border9", loadImage(BORDER_PATH + "border9.png"));
		images.put("border10", loadImage(BORDER_PATH + "border10.png"));
		images.put("border11", loadImage(BORDER_PATH + "border11.png"));
		images.put("border12", loadImage(BORDER_PATH + "border12.png"));
		images.put("border13", loadImage(BORDER_PATH + "border13.png"));
		images.put("border14", loadImage(BORDER_PATH + "border14.png"));
		images.put("border15", loadImage(BORDER_PATH + "border15.png"));
		images.put("border16", loadImage(BORDER_PATH + "border16.png"));
		images.put("border17", loadImage(BORDER_PATH + "border17.png"));

		// images.put("border18", loadImage(BORDER_PATH+"border18.png"));
		// images.put("border19", loadImage(BORDER_PATH+"border19.png"));

		images.put("border20", loadImage(BORDER_PATH + "border20.png"));
		images.put("border21", loadImage(BORDER_PATH + "border21.png"));
		images.put("border22", loadImage(BORDER_PATH + "border22.png"));
		images.put("border23", loadImage(BORDER_PATH + "border23.png"));
		images.put("border24", loadImage(BORDER_PATH + "border24.png"));
		images.put("border25", loadImage(BORDER_PATH + "border25.png"));
		images.put("border26", loadImage(BORDER_PATH + "border26.png"));
		images.put("border27", loadImage(BORDER_PATH + "border27.png"));

		// creatures
		
		//-- Pacman
		images.put("pacman", loadImage(CREATURE_PATH + "pacman_eat.gif"));

		images.put("pacman_stop", loadImage(CREATURE_PATH + "pacman.png"));
		images.put("pacman_no", loadImage(CREATURE_PATH + "pacman.png"));
		images.put("pacman_up", loadImage(CREATURE_PATH + "pacman_up.png"));
		images.put("pacman_down", loadImage(CREATURE_PATH + "pacman_down.png"));
		images.put("pacman_left", loadImage(CREATURE_PATH + "pacman_left.png"));
		images.put("pacman_right", loadImage(CREATURE_PATH + "pacman_right.png"));
		//images.put("pacman_right", loadImage(CREATURE_PATH + "pacman_eat.gif"));

		//-- Ghosts

		images.put("vulnerable_on", loadImage(CREATURE_PATH + "ghost_vulnerable.png"));
		images.put("vulnerable_on_near_end", loadImage(CREATURE_PATH + "ghost_vulnerable_near_end.gif"));

		//-- Blinky
		images.put("blinky", loadImage(CREATURE_PATH + "blinky_up.png"));
		images.put("blinky_stop", loadImage(CREATURE_PATH + "blinky_down.png"));
		images.put("blinky_no", loadImage(CREATURE_PATH + "blinky_down.png"));
		images.put("blinky_up", loadImage(CREATURE_PATH + "blinky_up.png"));
		images.put("blinky_down", loadImage(CREATURE_PATH + "blinky_down.png"));
		images.put("blinky_left", loadImage(CREATURE_PATH + "blinky_left.png"));
		images.put("blinky_right", loadImage(CREATURE_PATH + "blinky_right.png"));
		
		//-- Clyde
		images.put("clyde", loadImage(CREATURE_PATH + "clyde_up.png"));
		images.put("clyde_stop", loadImage(CREATURE_PATH + "clyde_down.png"));
		images.put("clyde_no", loadImage(CREATURE_PATH + "clyde_down.png"));
		images.put("clyde_up", loadImage(CREATURE_PATH + "clyde_up.png"));
		images.put("clyde_down", loadImage(CREATURE_PATH + "clyde_down.png"));
		images.put("clyde_left", loadImage(CREATURE_PATH + "clyde_left.png"));
		images.put("clyde_right", loadImage(CREATURE_PATH + "clyde_right.png"));
		
		//-- Pinky
		images.put("pinky", loadImage(CREATURE_PATH + "pinky_up.png"));
		images.put("pinky_stop", loadImage(CREATURE_PATH + "pinky_down.png"));
		images.put("pinky_no", loadImage(CREATURE_PATH + "pinky_down.png"));
		images.put("pinky_up", loadImage(CREATURE_PATH + "pinky_up.png"));
		images.put("pinky_down", loadImage(CREATURE_PATH + "pinky_down.png"));
		images.put("pinky_left", loadImage(CREATURE_PATH + "pinky_left.png"));
		images.put("pinky_right", loadImage(CREATURE_PATH + "pinky_right.png"));
		
		//-- Inky
		images.put("inky", loadImage(CREATURE_PATH + "inky_up.png"));
		images.put("inky_stop", loadImage(CREATURE_PATH + "inky_down.png"));
		images.put("inky_no", loadImage(CREATURE_PATH + "inky_down.png"));
		images.put("inky_up", loadImage(CREATURE_PATH + "inky_up.png"));
		images.put("inky_down", loadImage(CREATURE_PATH + "inky_down.png"));
		images.put("inky_left", loadImage(CREATURE_PATH + "inky_left.png"));
		images.put("inky_right", loadImage(CREATURE_PATH + "inky_right.png"));
		
		// pills
		images.put("pill", loadImage(BONUS_PATH + "pill.png"));
		images.put("power_pill", loadImage(BONUS_PATH + "power_pill.png"));

		// fruits
		images.put("cherry", loadImage(BONUS_PATH + "cherry.png"));
	}

	private final ImageIcon loadImage(final String path) {
		return new ImageIcon(getClass().getResource(path));
	}

	public final Image getImage(final String imageName) {
		return images.get(imageName).getImage();
	}
	
	public final ImageIcon getImageIcon(final String imageName) {
		return images.get(imageName);
	}

}